package jp.co.ricoh.melody.utils;

import android.util.Log;

import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

import jp.co.ricoh.melody.application.BaseApplication;

/**
 * Created by taoli on 2016/12/14.
 */

public class HDDUtil {
    public static boolean copySdcardFile(String fromFile, String toFile) {
        BaseApplication app= BaseApplication.getInstance();
        try {
            Log.i("taotest", "taotest123");
            if (!app.lockPowerMode()) {
                Log.i("SmartDocScan Lock", "lockPowerMode failed. ");
            }
            if (!app.lockOffline()) {
                Log.i("SmartDocScan Lock", "lockOffline failed. ");
            }
            if (!app.lockPanelOff()) {
                Log.i("SmartDocScan Lock", "lockPanleOff failed. ");
            }
            if (!app.lockPowerOff()) {
                Log.i("SmartDocScan Lock", "lockPowerOff failed. ");
            }
            Log.i("taotest", "taotest");
            InputStream fosfrom = new FileInputStream(fromFile);
            FileOutputStream fosto = new FileOutputStream(toFile);
            byte bt[] = new byte[1024*5];
            int c;
            while ((c = fosfrom.read(bt)) > 0) {
                fosto.write(bt, 0, c);
                fosto.flush();
            }
            fosto.getFD().sync();
            fosfrom.close();
            fosto.close();

            app.unlockPowerMode();
            app.unlockOffline();
            app.unlockPanelOff();
            app.unlockPowerOff();

            return true;
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }
    }
}
